<template>
	<view class="content" :style="'background:'+publicTextColor.app_bg_color+';'">
		<view class="topTitle" :style="'top:'+zhuangtai+'px'">
			<image class="back" @click="backClick" :src="publicimg.btn_back" mode=""></image>
			<view class="" style="font-size: 32rpx;">
				
			</view>
		</view>
		<image style="width: 750rpx;height: 100%;" :src="poster_image" mode="widthFix"></image>
		<view class="bottom-btn" @click="downLoadPoster">
			<image class="bgimgpublic" style="z-index: 0;" :src="publicimg.btn_lg_warm" mode=""></image>
			<text class="font28" :style="{color:publicTextColor.font_1st_color+';','z-index':'1;'}">保存海报</text>
		</view>
	</view>
</template>

<script>
	var util = require('@/js/util.js')
	export default {
		data() {
			return {
				publicTextColor:'',
				publicimg:'',
				zhuangtai:0,
				poster_image:'',
			};
		},
		onShow() {
			let that = this
			let aniosgaodu = 0
			uni.getSystemInfo({
				success: function(res) {
					console.log(res);
					that.zhuangtai = res.statusBarHeight;
					var a = res.model.split(' ');
					if (a[0] == 'iPhone') {
						aniosgaodu = 44;
					} else {
						aniosgaodu = 48;
					}
					that.zhuangtai = parseInt(that.zhuangtai)+4
					console.log(that.zhuangtai)
				}
			});
		},
		onLoad() {
			this.setcolorConfig()
			this.getSignIndex()
		},
		methods:{
			downLoadPoster(){
				let _this = this
				uni.getSetting({
					success(res) {
						console.log(res.authSetting)
						if(!res.authSetting['scope.writePhotosAlbum']){
							console.log("bbbb")
							uni.authorize({
								scope:"scope.writePhotosAlbum",
								success: (res) => {
									console.log("ddd",res)
								},
								fail: (e) => {
									console.log("CCC",e)
									uni.showModal({
										title:"提示",
										content:"保存海报需要您授权保存！",
										success: (res) => {
											if(res.confirm){
												uni.openSetting({
													success(res) {
														console.log(res.authSetting)
														if(res.authSetting["scope.writePhotosAlbum"]){
															_this.downloadfliea()
														}
													},
													fail: (e) => {
														console.log("EEE",e)
													}
												});
											}
										}
									})
								}
							})
						}else{
							console.log("aaaa")
							_this.downloadfliea()
						}
					}
				})
			},
			downloadfliea(){
				uni.showLoading({
					title:'保存中...'
				})
				console.log("1111",this.poster_image)
				uni.downloadFile({
					url:this.poster_image,
					success(res) {
						console.log(res)
						uni.saveImageToPhotosAlbum({
							filePath:res.tempFilePath,
							success:(res)=>{
								console.log(res)
								uni.hideLoading()
								uni.showToast({
									title:'保存成功！',
									icon:'success'
								})
							},
							fail:(e)=>{
								console.log(e)
							}
						})
					},
					fail(e) {
						console.log(e)
					}
				})
			},
			getSignIndex(){
				let _self = this
				uni.request({
					url: util.getUrl("member/poster"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.poster_image = res.data.data.poster
						}
					},
				});
			},
			setcolorConfig(){
				this.publicTextColor = uni.getStorageSync("diyColor")
				this.publicimg = uni.getStorageSync("diyImg")
			},
			backClick(){
				uni.navigateBack({
					
				})
			}
		}
	}
</script>

<style lang="scss">
	.bottom-btn{
		width: 690upx;
		height: 80upx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: fixed;
		bottom: 30upx;
		
	}
	.content{
		min-height: 100vh;
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
	}
	.topTitle{
		color: #FFFFFF;
		display: flex;
		align-items: center;
		height: 67rpx;
		justify-content: center;
		position: fixed;
		z-index: 10;
		width: 100%;
		.back{
			width: 20rpx;
			height: 31rpx;
			position: absolute;
			left: 31rpx;
		}
	}
</style>
